import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        int book = 12;
        int pen = 1;
        int rubber = 2;
        int cocal = 3;
        int snacks = 5;

        //打印价格表
        System.out.println("书本的价格为"+book+"元，总共的余额为20元");
        System.out.println("1、铅笔的价格为"+pen+"元");
        System.out.println("2、橡皮的价格为"+rubber+"元");
        System.out.println("3、可乐的价格为"+cocal+"元");
        System.out.println("4、零食的价格为"+snacks+"元");

        //键盘获取用户输入的选项
        System.out.println("请选择你要购买的商品");
        Scanner scnumber = new Scanner(System.in);
        String number = scnumber.next();

        //设置选项
        switch (number){
            case "1":
                int penmoney = 20-book;
                int pensum = penmoney/pen;
                int pensumpls = penmoney%pen;
                System.out.println("买完书后还可以买铅笔"+pensum+"支"+"剩余"+pensumpls+"元");
                break;
            case "2":
                int rubbermoney = 20-rubber;
                int rubbersum = rubbermoney/rubber;
                int rubbersumpls = rubbermoney%rubber;
                System.out.println("买完书后还可以买橡皮"+rubbersum+"个"+"剩余"+rubbersumpls+"元");
                break;
            case "3":
                int cocalmoney = 20-rubber;
                int cocalsum = cocalmoney/cocal;
                int cocalsumpls = cocalmoney%cocal;
                System.out.println("买完书后还可以买可乐"+cocalsum+"瓶"+"剩余"+cocalsumpls+"元");
                break;
            case "4":
                int snacksmoney = 20-snacks;
                int snackssum = snacksmoney/snacks;
                int snackssumpls = snacksmoney%snacks;
                System.out.println("买完书后还可以买零食"+snackssum+"包"+"剩余"+snackssumpls+"元");
                break;
            default:
                System.out.println("输入有误，请重新输入");
                a();
        }
    }
    public static  String a() {
        int book = 12;
        int pen = 1;
        int rubber = 2;
        int cocal = 3;
        int snacks = 5;

        //打印价格表
        System.out.println("书本的价格为"+book+"元，总共的余额为20元");
        System.out.println("1、铅笔的价格为"+pen+"元");
        System.out.println("2、橡皮的价格为"+rubber+"元");
        System.out.println("3、可乐的价格为"+cocal+"元");
        System.out.println("4、零食的价格为"+snacks+"元");
        System.out.println("请选择你要购买的商品");
        Scanner scnumber = new Scanner(System.in);
        String number = scnumber.next();

        //设置选项
        switch (number) {
            case "1":
                int penmoney = 20 - book;
                int pensum = penmoney / pen;
                int pensumpls = penmoney % pen;
                System.out.println("买完书后还可以买铅笔" + pensum + "支" + "剩余" + pensumpls + "元");
                break;
            case "2":
                int rubbermoney = 20 - rubber;
                int rubbersum = rubbermoney / rubber;
                int rubbersumpls = rubbermoney % rubber;
                System.out.println("买完书后还可以买橡皮" + rubbersum + "个" + "剩余" + rubbersumpls + "元");
                break;
            case "3":
                int cocalmoney = 20 - rubber;
                int cocalsum = cocalmoney / cocal;
                int cocalsumpls = cocalmoney % cocal;
                System.out.println("买完书后还可以买可乐" + cocalsum + "瓶" + "剩余" + cocalsumpls + "元");
                break;
            case "4":
                int snacksmoney = 20 - snacks;
                int snackssum = snacksmoney / snacks;
                int snackssumpls = snacksmoney % snacks;
                System.out.println("买完书后还可以买零食" + snackssum + "包" + "剩余" + snackssumpls + "元");
                break;
            default:
                System.out.println("输入有误，请重新输入");
                a();
        }
        return number;
    }
}